package com.gec.dao.Impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.gec.dao.GoodDao;
import com.gec.entity.Good;

public class GoodDaoImpl extends BaseDaoImpl<Good> implements GoodDao {

	@Override
	public void insert(Good a) {
		
	}

	@Override
	public int update(Good a) {
		return 0;
	}

	@Override
	public int delete(Integer id) {
		return 0;
	}

	@Override
	public Good selectById(Integer id) {
		return null;
	}

	@Override
	public List<Good> selectAll() {
		return null;
	}

	@Override
	protected Good mapper(ResultSet rs) throws SQLException {
		Good g = new Good();
		g.setId(rs.getInt(1));
		g.setName(rs.getString(2));
		g.setImg(rs.getString(3));
		g.setType_id(rs.getInt(4));
		g.setPrice(rs.getFloat(5));
		g.setCurPrice(rs.getFloat(6));
		g.setStore(rs.getInt(7));
		g.setState(rs.getInt(8));
		g.setPacking(rs.getFloat(9));
		g.setDepict(rs.getString(10));
		g.setTotal(rs.getInt(11));
		return g;
	}

	@Override
	public List<Good> selectListByType(int typeid) {
		return this.execQuery("select * from fs_goods where good_type_id = ? ", typeid);
	}

	@Override
	public List<Good> selectHot(int shopid) {
		String sql = "select * from fs_goods where good_id=?";
		return this.execQuery(sql, shopid);
	}

	@Override
	public Good selectShow(int shopid) {
		String sql = "select * from fs_goods where good_id=?";
		return (Good) this.execQuery(sql, shopid);
	}

	@Override
	public List<Good> selectListByShop(int shopid) {
		String sql = "select * from fs_goods where good_type_id "
				+ "in (select good_type_id from fs_goodtypes where good_type_id "
				+ "in (select shop_id from fs_shop where shop_id = ? ) )";
		return this.execQuery(sql, shopid);
	}

	@Override
	public List<Good> selectHots(int shopid) {
		String sql = "select * from fs_goods where good_type_id in"
				+ " (select good_type_id from fs_goodtypes where good_type_id in"
				+ " (select shop_id from fs_shop where shop_id = ? ) ) "
				+ "ORDER BY good_total DESC";
		return this.execQuery(sql, shopid);
	}

}
